import request from '@/utils/request'

// 查询监控设备列表
export function listDevice(query) {
  return request({
    url: '/campus/device/list',
    method: 'get',
    params: query
  })
}

// 查询监控设备详细
export function getDevice(deviceId) {
  return request({
    url: '/campus/device/' + deviceId,
    method: 'get'
  })
}

// 查询监控设备详细（包含关联信息）
export function getDeviceDetail(deviceId) {
  return request({
    url: '/campus/device/detail/' + deviceId,
    method: 'get'
  })
}

// 根据设备编码查询设备
export function getDeviceByCode(deviceCode) {
  return request({
    url: '/campus/device/code',
    method: 'get',
    params: { deviceCode }
  })
}

// 查询学校的设备列表
export function getDevicesBySchool(schoolId) {
  return request({
    url: '/campus/device/school',
    method: 'get',
    params: { schoolId }
  })
}

// 查询在线设备
export function getOnlineDevices(schoolId) {
  return request({
    url: '/campus/device/online',
    method: 'get',
    params: { schoolId }
  })
}

// 查询离线设备
export function getOfflineDevices(schoolId) {
  return request({
    url: '/campus/device/offline',
    method: 'get',
    params: { schoolId }
  })
}

// 查询故障设备
export function getFaultDevices(schoolId) {
  return request({
    url: '/campus/device/fault',
    method: 'get',
    params: { schoolId }
  })
}

// 查询维护设备
export function getMaintenanceDevices(schoolId) {
  return request({
    url: '/campus/device/maintenance',
    method: 'get',
    params: { schoolId }
  })
}

// 根据位置查询设备
export function getDevicesByLocation(latitude, longitude, distance) {
  return request({
    url: '/campus/device/location',
    method: 'get',
    params: { latitude, longitude, distance }
  })
}

// 查询设备状态统计
export function getDeviceStatusStatistics(schoolId) {
  return request({
    url: '/campus/device/statistics/status',
    method: 'get',
    params: { schoolId }
  })
}

// 查询设备类型统计
export function getDeviceTypeStatistics(schoolId) {
  return request({
    url: '/campus/device/statistics/type',
    method: 'get',
    params: { schoolId }
  })
}

// 查询设备心跳状态
export function getDeviceHeartbeatStatus(schoolId) {
  return request({
    url: '/campus/device/heartbeat',
    method: 'get',
    params: { schoolId }
  })
}

// 新增监控设备
export function addDevice(data) {
  return request({
    url: '/campus/device',
    method: 'post',
    data: data
  })
}

// 修改监控设备
export function updateDevice(data) {
  return request({
    url: '/campus/device',
    method: 'put',
    data: data
  })
}

// 删除监控设备
export function delDevice(deviceId) {
  return request({
    url: '/campus/device/' + deviceId,
    method: 'delete'
  })
}

// 更新设备心跳
export function updateDeviceHeartbeat(deviceId) {
  return request({
    url: '/campus/device/heartbeat',
    method: 'put',
    params: { deviceId }
  })
}

// 批量更新设备状态
export function updateDeviceStatusBatch(deviceIds, status) {
  return request({
    url: '/campus/device/updateStatusBatch',
    method: 'put',
    params: {
      deviceIds: deviceIds.join(','),
      status
    }
  })
}

// 批量更新设备在线状态
export function updateDeviceOnlineStatusBatch(deviceIds, onlineStatus) {
  return request({
    url: '/campus/device/updateOnlineStatusBatch',
    method: 'put',
    params: {
      deviceIds: deviceIds.join(','),
      onlineStatus
    }
  })
}

// 更新离线设备
export function updateOfflineDevices(timeoutMinutes) {
  return request({
    url: '/campus/device/updateOffline',
    method: 'put',
    params: { timeoutMinutes }
  })
}

// 校验设备编码
export function checkDeviceCodeUnique(deviceInfo) {
  return request({
    url: '/campus/device/checkDeviceCodeUnique',
    method: 'post',
    data: deviceInfo
  })
}

// 校验IP端口
export function checkIpPortUnique(deviceInfo) {
  return request({
    url: '/campus/device/checkIpPortUnique',
    method: 'post',
    data: deviceInfo
  })
}

// 重启设备
export function rebootDevice(deviceId) {
  return request({
    url: '/campus/device/reboot',
    method: 'post',
    params: { deviceId }
  })
}

// 设备截图
export function captureSnapshot(deviceId) {
  return request({
    url: '/campus/device/snapshot',
    method: 'post',
    params: { deviceId }
  })
}

// 导出监控设备
export function exportDevice(query) {
  return request({
    url: '/campus/device/export',
    method: 'post',
    data: query
  })
} 